// <copyright file="CustomRazorViewEngine.cs" company="Clever Software">
// Copyright (c) 2013, 2014 All Right Reserved, http://www.cleversoftware.by
//
// This source is subject to the Microsoft Permissive License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Clever Software</author>
// <email>info@cleversoftware.by</email>
// <date>2014-02-04</date> 
// <summary>CleverCMS source code</summary>



namespace CleverCMS.Core.Web
{
    using System.Collections.Generic;
    using System.Web.Mvc;

    public class CustomRazorViewEngine : RazorViewEngine
    {
        public CustomRazorViewEngine()
        {
            string[] mastersLocation = new[]{ string.Format("~/themes/{0}/views/{0}.cshtml", Utils.SkinName) };
            MasterLocationFormats = CustomViewEngineHelper.AddNewLocationFormats(new List<string>(MasterLocationFormats), mastersLocation);

            string[] viewsLocation = new[] { string.Format("~/themes/{0}/Views/{{1}}/{{0}}.cshtml", Utils.SkinName), string.Format("~/themes/{0}/Views/Shared/{{0}}.cshtml", Utils.SkinName) };
            ViewLocationFormats =  PartialViewLocationFormats =  CustomViewEngineHelper.AddNewLocationFormats(new List<string>(ViewLocationFormats), viewsLocation);
        }

        public override ViewEngineResult FindView(ControllerContext controllerContext,  string viewName, string masterName, bool useCache)
        {
            masterName = CustomViewEngineHelper.OverrideMasterPage(masterName, controllerContext);
            return base.FindView(controllerContext, viewName, masterName, useCache);
        }
    }
}